package com.qubuyer.business.mine.view

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.LifecycleOwner
import com.qubuyer.R
import com.qubuyer.business.mine.activity.ThirdAccountFragment
import com.qubuyer.core.app.BaseActivity
import com.qubuyer.customview.BaseDialog
import com.qubuyer.databinding.DialogSelectWithdrawAccountBinding
import com.qubuyer.repository.entitys.UserEntity

/**
 * @author Susong
 * @date 创建时间:2019/3/4
 * @description 提现说明dialog
 * & @version
 */
class SelectWithdrawAccountDialog(private val mContext: Context, lifecycleOwner: LifecycleOwner, userEntity: UserEntity?, private val block: (Int) -> Unit) : BaseDialog(mContext) {

    private val dataBinding: DialogSelectWithdrawAccountBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.dialog_select_withdraw_account, null, false)

    init {
        dataBinding.lifecycleOwner = lifecycleOwner
        dataBinding.host= this
        setContentView(dataBinding.root)
        setEntity(userEntity)
    }

    fun setEntity(entity: UserEntity?) {
        dataBinding.rlWechat.visibility = View.GONE
        dataBinding.rlAlipay.visibility = View.GONE
        if (entity?.is_bind_wx == 1) {
            dataBinding.rlWechat.visibility = View.VISIBLE
            dataBinding.rbWechat.isChecked = true
            dataBinding.rbAlipay.isChecked = false
        }
        if (entity?.is_bind_alipay == 1) {
            dataBinding.rlAlipay.visibility = View.VISIBLE
            if (entity.is_bind_wx != 1) {
                dataBinding.rbWechat.isChecked = false
                dataBinding.rbAlipay.isChecked = true
            }
        }
    }

    fun onClick(v: View) {
        when (v.id) {
            R.id.rl_wechat -> {
                dataBinding.rbWechat.isChecked = true
                dataBinding.rbAlipay.isChecked = false
                block.invoke(1)
            }
            R.id.rl_alipay -> {
                dataBinding.rbWechat.isChecked = false
                dataBinding.rbAlipay.isChecked = true
                block.invoke(2)
            }
            R.id.ll_add_account -> {
                (mContext as BaseActivity).swapContentFragment(ThirdAccountFragment())
            }
        }
        dismiss()
    }
}